home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
C64
/
G-Games
/
(c)gb.d64
/
towers.d
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2007-02-04
|
8KB
|
241 lines
1 REM - TOWERS OF BRAHMA FOR COMMODORE 64
2 REM - DANIEL MILLER
3 REM - 2815 34 STREET
4 REM - ASTORIA, QUEENS
5 REM - NEW YORK, NEW YORK 11103
6 REM - APRIL 22, 1983
7 REM ********************************
100 GOTO10000
302 POKE53281,1:ZZ=1:PRINTCL$;LEFT$(DO$,2);TAB(11);HDG$;
305 POKE55587,10:POKE1315,49:POKE55595,10:POKE1323,50:POKE55603,10:POKE1331,51
310 PRINT LEFT$(DO$,20);TAB(5);A$(1);LEFT$(DO$,9);TAB(11);A$(3);
320 PRINTLEFT$(DO$,9);TAB(19);A$(3);LEFT$(DO$,9);TAB(27);A$(3)
350 REM - PLACE SPRITES ON TOWER #1
360 POKEV+14,93:POKEV+15,160:POKEV+12,93:POKEV+13,151:POKEV+10,93:POKEV+11,142
365 POKEV+8,93:POKEV+9,133:POKEV+6,93:POKEV+7,124:POKEV+4,93:POKEV+5,115
368 POKEV+2,93:POKEV+3,106:POKEV+0,93:POKEV+1,97
370 IF YN$="Y" THEN N2=8-NUM:GOTO374
372 IF ZZ=0 THEN 397
373 PRINTLEFT$(DO$,22);TAB(8);NUM$;:INPUT NUM:N2=8-NUM:SP=0:IF NUM=8 THEN385
374 N4=N2
375 IF NUM<1 OR NUM>8 THEN PRINT LEFT$(DO$,22);TAB(5);SP$;:GOTO373
376 IF NUM=8 AND YN$="Y" THEN385
377 FOR X=1 TO N4
379 SP=SP+(2^(N4-1))
381 N4=N4-1:NEXT X
383 POKEV+21,(255-SP)
385 ZZ=0:FOR TM=1 TO 250:NEXT TM:PRINTLEFT$(DO$,22);TAB(5);SP$;
387 T1$="":T2$="":T3$="":N3=N2+1
388 FOR X=1 TO NUM:T1$=T1$+T4$(X):T2$=T2$+T5$(X):T3$=T3$+T6$(X):NEXT X
389 IF YN$="Y" THEN1060
392 FOR X=1 TO NUM:Y=2^X-1:NEXT X
393 NUM$=RV$+BL$+STR$(NUM)+RO$+SLV$(1)+RV$+BL$+STR$(Y)+SLV$(2):Y0=Y
394 PRINTLEFT$(DO$,22);TAB(6);NUM$;:FOR TM=1 TO 2000:NEXT TM
395 FOR TM=1 TO 250:NEXT TM:PRINTLEFT$(DO$,22);TAB(5);SP$;
397 PRINTLEFT$(DO$,22);TAB(6);F9$;" ";TAB(24);T9$;" ";
398 PRINTLEFT$(DO$,22);TAB(6);F9$;" ";CR$;
400 IF ZA=2 THEN422
420 GET TWR$(1):IF TWR$(1)="" THEN420
421 IF TWR$(1)<>"X" AND (TWR$(1)<"1" OR TWR$(1)>"3") THEN TWR$(1)="":GOTO420
422 PRINT RV$+RED$+TWR$(1)+RO$;
423 IF TWR$(1)="X" THEN1010
425 PRINTLEFT$(DO$,22);TAB(34);" ";CR$;
426 IF ZA=2 THEN432
430 GET TWR$(2):IF TWR$(2)="" THEN430
431 IF TWR$(2)<"1" OR TWR$(2)>"3" THEN TWR$(2)="":GOTO430
432 PRINT RV$+RED$+TWR$(2)+RO$;
450 ON VAL(TWR$(1)) GOTO 460,470,480
460 FOR X=1 TO NUM:IF MID$(T1$,X,1)="1" THEN465
462 NEXT X:LOC(1)=160:GOTO490
465 LOC(1)=T1(N2+X):T4$(N2+X)="0":GOTO490
470 FOR X=1 TO NUM:IF MID$(T2$,X,1)="1" THEN475
472 NEXT X:LOC(1)=160:GOTO490
475 LOC(1)=T2(N2+X):T5$(N2+X)="0":GOTO490
480 FOR X=1 TO NUM:IF MID$(T3$,X,1)="1" THEN485
482 NEXT X:LOC(1)=160:GOTO490
485 LOC(1)=T3(N2+X):T6$(N2+X)="0"
490 LC=LOC(1):GOSUB560:SP(1)=SP
500 ON VAL(TWR$(2)) GOTO 510,520,530
510 FOR X=1 TO NUM:IF MID$(T1$,X,1)="1" THEN515
512 NEXT X:LOC(2)=160:T4$(N2+X-1)="1":GOTO540
515 LOC(2)=T1(N2+X-1):T4$(N2+X-1)="1":GOTO540
520 FOR X=1 TO NUM:IF MID$(T2$,X,1)="1" THEN525
522 NEXT X:LOC(2)=160:T5$(N2+X-1)="1":GOTO540
525 LOC(2)=T2(N2+X-1):T5$(N2+X-1)="1":GOTO540
530 FOR X=1 TO NUM:IF MID$(T3$,X,1)="1" THEN535
532 NEXT X:LOC(2)=160:T6$(N2+X-1)="1":GOTO540
535 LOC(2)=T3(N2+X-1):T6$(N2+X-1)="1"
540 LC=LOC(2):GOSUB560:SP(2)=SP
550 T1$="":T2$="":T3$="":N5=N2+1
555 FOR X=N5 TO 8:T1$=T1$+T4$(X):T2$=T2$+T5$(X):T3$=T3$+T6$(X):NEXT X:GOTO570
560 IF LC=97 THEN SP=1:RETURN
561 IF LC=106 THEN SP=2:RETURN
562 IF LC=115 THEN SP=3:RETURN
563 IF LC=124 THEN SP=4:RETURN
564 IF LC=133 THEN SP=5:RETURN
565 IF LC=142 THEN SP=6:RETURN
566 IF LC=151 THEN SP=7:RETURN
567 IF LC=160 THEN SP=8:RETURN
570 ON VAL(TWR$(1)) GOTO 571,572,573
571 SQ%=R1%(1,SP(1)):R1%(1,SP(1))=8:GOTO574
572 SQ%=R2%(1,SP(1)):R2%(1,SP(1))=8:GOTO574
573 SQ%=R3%(1,SP(1)):R3%(1,SP(1))=8
574 ON VAL(TWR$(2)) GOTO 575,576,577
575 R1%(1,SP(2))=SQ%:GOTO580
576 R2%(1,SP(2))=SQ%:GOTO580
577 R3%(1,SP(2))=SQ%
580 ON VAL(TWR$(1)) GOTO 582,585,588
582 X1=93:GOTO590
585 X1=157:GOTO590
588 X1=222
590 ON VAL(TWR$(2)) GOTO 592,595,598
592 X2=93:GOTO600
595 X2=157:GOTO600
598 X2=222
600 REM - MOVE SPRITE
605 ON SQ%+1 GOTO 610,615,620,625,630,635,640,645
610 SP=0:SQ=1:GOTO705
615 SP=2:SQ=3:GOTO705
620 SP=4:SQ=5:GOTO705
625 SP=6:SQ=7:GOTO705
630 SP=8:SQ=9:GOTO705
635 SP=10:SQ=11:GOTO705
640 SP=12:SQ=13:GOTO705
645 SP=14:SQ=15
705 IF VAL(TWR$(1))>VAL(TWR$(2)) THEN740
710 FOR YY=LOC(1) TO 55 STEP-1:POKE V+SP,X1:POKE V+SQ,YY:NEXT YY
720 FOR XX=X1 TO X2:POKE V+SP,XX:POKE V+SQ,55:NEXT XX
730 FOR YY=55 TO LOC(2)+1:POKE V+SP,X2:POKE V+SQ,YY:NEXT YY:GOTO790
740 FOR YY=LOC(1) TO 55 STEP-1:POKE V+SP,X1:POKE V+SQ,YY:NEXT YY
750 FOR XX=X1 TO X2 STEP-1:POKE V+SP,XX:POKE V+SQ,55:NEXT XX
770 FOR YY=55 TO LOC(2):POKEV+SP,X2:POKEV+SQ,YY:NEXT YY
790 MV=MV+1:PRINTLEFT$(DO$,24);TAB(17);MV$+RV$+B2$+STR$(MV)+RO$;
793 IF ZA=2 THEN MW=MW+1:GOTO1105:REM - COMPUTER'S NEXT MOVE
798 GOTO397:REM - PLAYER'S NEXT MOVE
1000 REM - COMPUTER SOLUTION
1010 TWR$(1)="":PRINTLEFT$(DO$,24);TAB(7);CMP$;
1015 GET YN$:IF YN$="" THEN1015
1017 IF YN$="Y" THEN1020
1018 IF YN$<>"N" THEN YN$="":GOTO1010
1020 PRINT RV$+BL$+" "+YN$+RO$;:FOR TM=1 TO 500:NEXT TM:IF YN$="Y" THEN1050
1030 FOR TM=1 TO 1000:NEXT TM
1031 PRINTLEFT$(DO$,24);TAB(7);SP$;LEFT$(DO$,24);TAB(9);EN$;
1033 GET RT$:IF RT$<>CHR$(13) THEN1033
1035 POKE V+21,0:PRINT CL$;:END
1050 SP=0:MV=0:MW=1:GOTO3100
1060 YN$="":ZA=2:PRINTLEFT$(DO$,24);TAB(7);SP$;
1105 BI$="":FOR X=1 TO 8:BI$(X)="0":NEXT X
1106 IF MV=Y0 THEN1030
1110 C2=0:C3=0:C4=0:C5=0:C6=0:ZA=2
1120 DEC=MW
1130 FOR Y=0 TO 8:IF INT(2^Y)>DEC THEN Y=Y-1:BI$(Y)="1":GOTO1150
1140 BI$(Y)="0":NEXT Y
1150 DEC=DEC-2^Y:IF DEC=0 THEN1170
1160 GOTO1130
1170 FOR Y=7 TO 0 STEP-1:BI$=BI$+BI$(Y):NEXT Y
1200 FOR X=8 TO 1 STEP-1:IF MID$(BI$,X,1)="0" THEN C2=C2+1:NEXT X
1201 C2=C2+1
1220 RI%=C2+NUM-1
1221 IF NUM=2 THEN RI%=RI%+4:GOTO1230
1222 IF NUM=3 THEN RI%=RI%+2:GOTO1230
1223 IF NUM=4 THEN1230
1224 IF NUM=5 THEN RI%=RI%-2:GOTO1230
1225 IF NUM=6 THEN RI%=RI%-4:GOTO1230
1226 IF NUM=7 THEN RI%=RI%-6:GOTO1230
1227 IF NUM=8 THEN RI%=ABS(RI%-8)
1230 FOR X=1 TO 8:IF R1%(1,X)=RI% THEN TWR$(1)="1":GOTO1260
1240 NEXT X:FOR X=1 TO 8:IF R2%(1,X)=RI% THEN TWR$(1)="2":GOTO1260
1250 NEXT X:TWR$(1)="3"
1260 L$=TWR$(1)
1300 FOR X=1 TO 8:IF MID$(BI$,X,1)="1" THEN C3=C3+1:NEXT X:GOTO1330
1310 NEXT X
1330 IF C3>1 THEN1400
1340 IF VAL(T1$)=0 THEN TWR$(2)="1":GOTO397
1350 IF VAL(T2$)=0 THEN TWR$(2)="2":GOTO397
1360 IF VAL(T3$)=0 THEN TWR$(2)="3":GOTO397
1400 FOR X=8 TO 1 STEP-1:C4=C4+1:IF MID$(BI$,X,1)="0" THEN NEXT X
1410 C6=C4
1420 FOR X=8-C4 TO 1 STEP-1:C6=C6+1:IF MID$(BI$,X,1)="0"THEN C5=C5+1:NEXT X
1440 RJ%=C6+NUM-1
1441 IF NUM=2 THEN RJ%=RJ%+4:GOTO1450
1442 IF NUM=3 THEN RJ%=RJ%+2:GOTO1450
1443 IF NUM=4 THEN1450
1444 IF NUM=5 THEN RJ%=RJ%-2:GOTO1450
1445 IF NUM=6 THEN RJ%=RJ%-4:GOTO1450
1446 IF NUM=7 THEN RJ%=RJ%-6:GOTO1450
1447 IF NUM=8 THEN RJ%=ABS(RJ%-8)
1450 FOR X=1 TO 8:IF R1%(1,X)=RJ% THEN TX$="1":GOTO1480
1460 NEXT X:FOR X=1 TO 8:IF R2%(1,X)=RJ% THEN TX$="2":GOTO1480
1470 NEXT X:TX$="3"
1480 M$=TX$
1490 IF C5=0 OR C5=2 OR C5=4 OR C5=6 THEN TWR$(2)=TX$:GOTO397
1500 REM IF (C5/2)=INT(C5/2) OR C5=0 THEN TWR$(2)=TX$:GOTO397
1510 IF L$="1" AND M$="2" THEN TWR$(2)="3":GOTO397
1520 IF L$="1" AND M$="3" THEN TWR$(2)="2":GOTO397
1530 IF L$="2" AND M$="3" THEN TWR$(2)="1":GOTO397
1540 IF L$="2" AND M$="1" THEN TWR$(2)="3":GOTO397
1550 IF L$="3" AND M$="1" THEN TWR$(2)="2":GOTO397
1560 IF L$="3" AND M$="2" THEN TWR$(2)="1":GOTO397
1600 STOP
3000 REM - BUILD SPRITES
3100 V=53248:POKEV+21,255:POKEV+23,255:POKEV+29,255
3110 POKE2040,192:POKE2041,193:POKE2042,194:POKE2043,195:POKE2044,196
3112 POKE2045,197:POKE2046,198:POKE2047,199
3120 POKEV+39,3:POKEV+40,15:POKEV+41,13:POKEV+42,9:POKEV+43,14:POKEV+44,5
3125 POKE V+45,8:POKEV+46,0
3130 RESTORE:N0=12288:FOR X=1 TO 8:FOR N=0 TO 62:READ Q:POKE N0+N,Q:NEXT N
3132 N0=N0+64:NEXT X
3200 T1$="11111111":T2$="00000000":T3$="00000000"
3210 FOR X=1 TO 8:T4$(X)=MID$(T1$,X,1):NEXT X
3220 FOR X=1 TO 8:T5$(X)=MID$(T2$,X,1):NEXT X
3230 FOR X=1 TO 8:T6$(X)=MID$(T3$,X,1):NEXT X
3240 Z%=97:FOR X=1 TO 8:T1(X)=Z%:T2(X)=Z%:T3(X)=Z%:Z%=Z%+9:NEXT X
3250 Y%=0:FOR X=1 TO 8:R1%(1,X)=Y%:Y%=Y%+1:NEXT X
3252 FOR X=1 TO 8:R2%(1,X)=9:R3%(1,X)=9:NEXT X
3260 IF YN$="Y" THEN360
3900 GOTO302
10000 REM - BUILD CHARACTER GRAPHICS
10100 BLK$=CHR$(144):RED$=CHR$(28):YEL$=CHR$(158):B2LU$=CHR$(31):CY$=CHR$(159)
10150 RV$=CHR$(18):RO$=CHR$(146)
10160 CL$=CHR$(147):DW$=CHR$(17):LF$=CHR$(157)
10170 FOR X=1 TO 24:DO$=DO$+DW$:NEXT X:DO$=CHR$(19)+DO$
10200 A$(1)=RV$+B2$+" "+RO$
10210 A$(2)=RV$+YEL$+" "+DW$+LF$
10215 FOR X=1 TO 10:A$(3)=A$(3)+A$(2):NEXT X
10217 A$(3)=A$(3)+" "+RO$
10300 HDG$=RV$+WH$+"TOWERS OF BRAHMA"+RO$
10320 NUM$=RV$+B2$+"NUMBER OF RINGS (2 - 8)"+RO$
10330 SP$=" "
10340 F9$=RV$+BL$+"FROM TOWER #"+RO$:T9$=RV$+BL$+"TO TOWER #"+RO$
10350 CR$=RV$+CY$+" "+RO$
10360 SLV$(1)=RV$+BL$+" RINGS REQUIRES"+RO$:SLV$(2)=RV$+BL$+" MOVES."+RO$
10370 MV$=RV$+B2$+"MOVE #"+RO$
10380 CMP$=RV$+BL$+"COMPUTER SOLUTION (Y/N) ?"+RO$
10390 EN$=RV$+BL$+"PRESS <RETURN> TO END"+RO$
10600 GOTO3100
10799 REM - DATA FOR SPRITES
10800 REM - SPRITE 0
10810 DATA ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:REM 53 COMMAS
10820 DATA 1,255,128,1,255,128,1,255,128
10900 REM - SPRITE 1
10910 DATA ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
10920 DATA 3,255,192,3,255,192,3,255,192
11000 REM - SPRITE 2
11010 DATA ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
11020 DATA 7,255,224,7,255,224,7,255,224
11100 REM - SPRITE 3
11110 DATA ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
11120 DATA 15,255,240,15,255,240,15,255,240
11200 REM - SPRITE 4
11210 DATA ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
11220 DATA 31,255,248,31,255,248,31,255,248
11300 REM - SPRITE 5
11310 DATA ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
11320 DATA 63,255,252,63,255,252,63,255,252
11400 REM - SPRITE 6
11410 DATA ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
11420 DATA 127,255,254,127,255,254,127,255,254
11500 REM - SPRITE 7
11510 DATA ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
11520 DATA 255,255,255,255,255,255,255,255,255